package com.car.slave.im.model.user;

import java.util.Map;

import org.json.JSONObject;

import android.content.ContentValues;
import android.database.Cursor;

import com.car.slave.im.model.IMMessage;
import com.car.slave.im.util.IMTool;

@SuppressWarnings("serial")
public class IMTextMessage extends IMUserMessage {
	
	public static final String COLUMN_MESSAGE_CONTENT = "messageContent";

	public String content;
	
	public IMTextMessage() {
		super();
	}

	/**
	 * 构造发送的消息.
	 * @param content
	 */
	public IMTextMessage(String content) {
		super(IMUserMessage.getAutoMessageid(), TYPE_TEXT, 0);
		this.content = content;
	}
	
	/**
	 * 构造接送的消息.
	 * @param messageId
	 * @param content
	 */
	public IMTextMessage(String messageId, String content) {
		super(messageId, TYPE_TEXT, 1);
		this.content = content;
	}
	
	@Override
	public byte[] getSendBuffer() {
		Map<String, String> jsonMap = getJsonMap();
		jsonMap.put("content", content);
		return IMTool.getIoBuffer(IMMessage.CMD_USER_CHAT_MSG, new JSONObject(jsonMap).toString());
	}
	
	@Override
	public void cursorToMessage(Cursor cursor) {
		super.cursorToMessage(cursor);
		content = cursor.getString(cursor.getColumnIndex(COLUMN_MESSAGE_CONTENT));
	}
	
	@Override
	public ContentValues getContentValues() {
		ContentValues cv = super.getContentValues();
		cv.put(COLUMN_MESSAGE_CONTENT, content);
		return cv;
	}

}
